<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('课程管理列表')"/>
    <th:block th:include="include :: select2-css"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <label>课程标题：</label>
                            <input type="text" name="courseName"/>
                        </li>
                        <li>
                            <label>专题名称：</label>
                            <select class="form-control" name="subjectId">
                                <option value="">全部</option>
                                <th:block th:each="subject:${subjectList}" th:object="${subject}">
                                    <option th:value="*{id}" th:text="*{subjectName}"></option>
                                </th:block>
                            </select>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.addFull()" shiro:hasPermission="course:course:add">
                <i class="fa fa-plus"></i> 添加
            </a>
            <a class="btn btn-primary single disabled" onclick="$.operate.editFull()"
               shiro:hasPermission="course:course:edit">
                <i class="fa fa-edit"></i> 修改
            </a>
            <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()"
               shiro:hasPermission="course:course:remove">
                <i class="fa fa-remove"></i> 删除
            </a>
            <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="course:course:export">
                <i class="fa fa-download"></i> 导出
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: select2-js"/>
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('course:course:edit')}]];
    var chapterFlag = [[${@permission.hasPermi('course:course:chapter')}]];
    var removeFlag = [[${@permission.hasPermi('course:course:remove')}]];
    var courseIfDicountDatas = [[${@dict.getType('course_if_discount')}]];
    var courseIfFreeDatas = [[${@dict.getType('course_if_free')}]];
    var courseIfForeignDatas = [[${@dict.getType('course_if_foreign')}]];
    var courseOnlineStateDatas = [[${@dict.getType('course_online_status')}]];
    var prefix = ctx + "course/course";

    var curWwwPath = window.location.href
    var pathname = window.document.location.pathname;
    var pos = curWwwPath.indexOf(pathname);
    var chapterUrl = curWwwPath.substring(0, pos) + ctx + "chapter/chapter/";
    $(function () {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            modalName: "课程管理",
            columns: [{
                checkbox: true
            },
                {
                    field: 'id',
                    title: '表id',
                    visible: false
                },
                {
                    field: 'courseName',
                    title: '课程标题',
                    sortable: true
                },
                {
                    field: 'courseIfForeign',
                    title: '是否对外',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(courseIfForeignDatas, value);
                    },
                    sortable: true
                },
                {
                    field: 'courseIfFree',
                    title: '是否免费',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(courseIfFreeDatas, value);
                    },
                    sortable: true
                },

                {
                    field: 'courseIfDicount',
                    title: '是否打折',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(courseIfDicountDatas, value);
                    },
                    sortable: true
                },
                {
                    field: 'courseOriginalPrice',
                    title: '课程价格',
                    sortable: true
                },
                {
                    field: 'courseDicountPrice',
                    title: '折后价',
                    sortable: true
                },
                {
                    field: 'courseDiscountRemark',
                    title: '打折描述'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.editFull(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-success btn-xs ' + chapterFlag + '" href="javascript:void(0)" onclick="detail(\'' + row.id + '\')"><i class="fa fa-book"></i>章节</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });

    /*章节*/
    function detail(id) {
        var url = chapterUrl + id;
        $.modal.openTab("章节", url);
    }
</script>
</body>
</html>